﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;

namespace SQLCDCIDLoader
{
    class Program
    {
        static void Main(string[] args)
        {

            string sqljobid = args[0];
            string srcserver = args[1];
            string srcuser = args[2];
            string epwd = args[3];

            //===================================================================================================

            //  59445abf-f3fc-43bd-9c7c-93f32a297604 .\dmsql2014 $$@#$$ dJWJ263s5YkWlwrvfWg1Cw==
            //string sqljobid = "fdd200d3-d8ac-43ff-9d37-6aae90948b14";
            //string srcserver = ".\\dmsql2014";
            //string srcuser = "$$@#$$";
            //string epwd = "dJWJ263s5YkWlwrvfWg1Cw==";
         
            if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)+ "\\" + "SQLCDCApp"))
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\" + "SQLCDCApp");
            }
            string logfile = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\" + "SQLCDCApp\\sqlcdcapp_log.log";
            LogRoller lr = new LogRoller(logfile);
            
            try
            {
              
                lr.LogMessage("Incremental load initiated by SQLJobID " + sqljobid);
                SQLCDCDAL obj = new SQLCDCDAL(sqljobid, srcserver, srcuser, epwd,logfile);
           
                obj.fn_IncrementalDataLoad();
            }catch(Exception ex)
            {
                lr.LogException(ex);
            }

        }

    }
}
